﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;

namespace SQLToClass
{
    /// <summary>
    /// Connection management
    /// Created by: Dinh Quoc Vuong
    /// Created date: Oct 10th 2011
    /// </summary>
    public static class Connection
    {
        /// <summary>
        /// Get connection
        /// </summary>
        /// <returns></returns>
        private static DbConnection GetConnection(ConnectionType type, string connectionString)
        {
            DbConnection conn = null;
            switch (type)
            {
                case ConnectionType.SqlServer:
                    conn = new SqlConnection(connectionString);
                    break;
                case ConnectionType.MySql:
                    conn = new MySqlConnection(connectionString);
                    break;
                default:
                    break;
            }
            
            return conn;
        }

        /// <summary>
        /// Get command
        /// </summary>
        /// <returns></returns>
        public static DbCommand GetCommand(ConnectionType type, string connectionString)
        {
            DbConnection conn = GetConnection(type, connectionString);
            DbCommand cmd = conn.CreateCommand();
            return cmd;
        }
    }
}
